package com.bilibili.api;

import com.bilibili.api.support.UserSupport;
import com.bilibili.domain.JsonResponse;
import com.bilibili.domain.entity.FollowingGroup;
import com.bilibili.domain.entity.UserFollowing;
import com.bilibili.service.FollowingGroupService;
import com.bilibili.service.UserFollowingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * projectName:com.bilibili.api
 *
 * @author 飞
 * @create by 2024/6/69:55
 * description:
 */
@RestController
@RequestMapping("/following")
@Api("用户关注相关接口")
public class UserFollowingController {
    @Resource
    private UserSupport userSupport;
    @Resource
    private UserFollowingService userFollowingService;
    @Resource
    private FollowingGroupService followingGroupService;


    @PostMapping("/add")
    @ApiOperation("添加用户关注")
    public JsonResponse<String> addUserFollowings(@RequestBody UserFollowing userFollowing)
    {
        Long userId = userSupport.getCurrentUserId();
        userFollowing.setUserId(userId);
        userFollowingService.addUserFollowings(userFollowing);
        return JsonResponse.success();
    }

    @GetMapping("/get")
    @ApiOperation("获取用户关注列表")
    public JsonResponse<List<FollowingGroup>> getUserFollowings(){
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> result = userFollowingService.getUserFollowings(userId);
        return new JsonResponse<>(result);
    }


    @GetMapping("/fans")
    @ApiOperation("获取用户粉丝列表")
    public JsonResponse<List<UserFollowing>> getUserFans(){
        Long userId = userSupport.getCurrentUserId();
        List<UserFollowing> result = userFollowingService.getUserFans(userId);
        return new JsonResponse<>(result);
    }

    @PostMapping("/add-groups")
    @ApiOperation("新建用户分组")
    public JsonResponse<Long> addUserFollowingGroups(@RequestBody FollowingGroup followingGroup)
    {
        Long userId = userSupport.getCurrentUserId();
        followingGroup.setUserId(userId);
        Long groupId = followingGroupService.addUserFollowingGroups(followingGroup);
        return new JsonResponse<>(groupId);
    }

    @GetMapping("/get-groups")
    @ApiOperation("获取用户分组")
    public JsonResponse<List<FollowingGroup>> getUserFollowingGroups(){
        Long userId = userSupport.getCurrentUserId();
        List<FollowingGroup> followingGroups = followingGroupService.getUserFollowingGroups(userId);
        return new JsonResponse<>(followingGroups);
    }
}
